package cn.dansj.handler.interfaces;

import cn.dansj.annotation.MarkAsApi;
import cn.dansj.common.utils.json.DictMap;
import cn.dansj.common.utils.transfer.Md5Utils;
import cn.dansj.common.utils.transfer.Transformation;
import cn.dansj.handler.InterfaceHandler;

import java.util.Map;

@MarkAsApi
public class EdgeAddEngine extends InterfaceHandler {
    private static final String insert = "insert into x_edge_component(component, title, url, id) values(?,?,?,?)";
    private static final String delete = "delete from x_edge_component where id = ? and component = 'engine'";

    @Override
    public Object execute(Map<String, Object> paramsMap) {
        String component = "engine";
        String url = Transformation.toString(paramsMap.get("searchUrl"));
        String title = Transformation.toString(paramsMap.get("title"));
        String id = Md5Utils.md5(url);
        jdbcTemplate.update(delete, id);
        jdbcTemplate.update(insert, component, title, url, id);
        return DictMap.of("id", id, "title", title, "searchUrl", url);
    }
}